﻿using Com.JunCaiSoft.AutoMapper;
using Com.JunCaiSoft.Common.AssistClass;
using Com.JunCaiSoft.Common.ExchangeData;
using Com.JunCaiSoft.Permission.Entity;
using Com.JunCaiSoft.Permission.Model;
using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Com.JunCaiSoft.Permission
{
    public static class PermissionAutoMapperConfigure
    {
        public static void CreatePermissionMapper(IApplicationBuilder app)
        {
            var creator = app.UseAutoMapper();

            #region 用户映射表
            creator.CreateMap<User, UserInfo>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.NumCode, opt => opt.MapFrom(src => src.NumCode))
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.RealName))
                .ForMember(dest => dest.AccessToken, opt => opt.Ignore())
                .ForMember(dest => dest.Authorizes, opt => opt.Ignore())
                .ForMember(dest => dest.Begins, opt => opt.Ignore())
                .ForMember(dest => dest.Expires, opt => opt.Ignore());
            creator.CreateMap<UserView, User>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.Num, opt => opt.MapFrom(src => src.NumCode))
                .ForMember(dest => dest.NumCode, opt => opt.MapFrom(src => src.NumCode))
                .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.UserName))
                .ForMember(dest => dest.Password, opt => opt.Ignore())
                .ForMember(dest => dest.RealName, opt => opt.MapFrom(src => src.RealName))
                .ForMember(dest => dest.SessionTimeout, opt => opt.MapFrom(src => src.SessionTimeout))
                .ForMember(dest => dest.Positions, opt => opt.Ignore())
                .ForMember(dest => dest.AuthrorizeTree, opt => opt.MapFrom(src => src.AuthrorizeTree))
                .ForMember(dest => dest.LastIPAddress, opt => opt.MapFrom(src => src.LastIPAddress))
                .ForMember(dest => dest.AccessFailedCount, opt => opt.Ignore())
                .ForMember(dest => dest.ConcurrencyStamp, opt => opt.Ignore())
                .ForMember(dest => dest.Email, opt => opt.Ignore())
                .ForMember(dest => dest.EmailConfirmed, opt => opt.Ignore())
                .ForMember(dest => dest.LockoutEnabled, opt => opt.Ignore())
                .ForMember(dest => dest.LockoutEnd, opt => opt.Ignore())
                .ForMember(dest => dest.NickName, opt => opt.Ignore())
                .ForMember(dest => dest.NormalizedEmail, opt => opt.Ignore())
                .ForMember(dest => dest.NormalizedUserName, opt => opt.Ignore())
                .ForMember(dest => dest.PasswordHash, opt => opt.Ignore())
                .ForMember(dest => dest.PhoneNumber, opt => opt.Ignore())
                .ForMember(dest => dest.PhoneNumberConfirmed, opt => opt.Ignore())
                .ForMember(dest => dest.TwoFactorEnabled, opt => opt.Ignore())
                .ForMember(dest => dest.SecurityStamp, opt => opt.Ignore())
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime));
            creator.CreateMap<User, UserView>()
                .ForMember(dest => dest.CurrentPlayRole,opt => opt.Ignore());
            creator.CreateMap<User, UserItem>();
            #endregion


        }
    }
}
